Skip to content

fix(api): return 400 for a bad cursor on globally paginated endpoints - #10487

Open
Darshanpawar7 wants to merge 1 commit into
makeplane:previewfrom
Darshanpawar7:fix/global-paginator-cursor
Open

Darshanpawar7 wants to merge 1 commit into
makeplane:previewfrom
Darshanpawar7:fix/global-paginator-cursor

Conversation

@Darshanpawar7

@Darshanpawar7 Darshanpawar7 commented Dec 5, 2026 •

Copy link
Copy Markdown
Contributor

Description

plane/utils/global_paginator.py now rejects a bad cursor with 400 (ParseError, "Invalid cursor parameter.") instead of 500, as BasePaginator.paginate already does:

  • a cursor that isn't page_size:page:offset: PaginateCursor.from_string raised ValueError, which paginate didn't catch;
  • a page size of 0 or less: ceil(total_results / page_size) raised ZeroDivisionError, and a negative size failed on the queryset slice;
  • a negative page.

This covers v2 work items, work item versions, and work item and intake description versions. Valid cursors behave as before.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • Feature (non-breaking change which adds functionality)
  • Improvement (change that would cause existing functionality to not work as expected)
  • Code refactoring
  • Performance improvements
  • Documentation update

Test Scenarios

  • New plane/tests/contract/app/test_global_paginator_cursor_app.py: six bad cursors (abc, 10:0, x:0:0, 0:0:0, -5:0:0, 10:-1:0) return 400 on all four endpoints, and 10:0:0 still returns 200. The six bad-cursor tests fail on preview (500) and pass with this change.
  • ruff check and ruff format --check pass on the changed files. The backend suite passes (1,845 tests); four asset tests that need object storage (test_generic_asset_patch_scope.py, test_static_asset_disposition_app.py) fail the same way on preview without this change.

References

Fixes #10486

Summary by CodeRabbit

  • Bug Fixes
    • Invalid pagination cursors now return a clear error instead of causing a server error.
    • Cursors with zero or negative page sizes, or negative page numbers, are rejected. Valid cursors continue to work.

plane.utils.global_paginator raised ValueError for a cursor that isn't
page_size:page:offset, ZeroDivisionError for a page size of 0 and an error on
the queryset slice for a negative one, so v2 work items, work item versions and
description versions returned 500. Reject these cursors with ParseError, as
BasePaginator does.
Copilot AI balanced review requested due to automatic review settings December 5, 2026 10:41

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@coderabbitai

coderabbitai Bot commented Dec 5, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The global paginator now returns a parse error for malformed cursors and rejects nonpositive page sizes and negative pages. Contract tests check invalid and valid cursors across four project-scoped endpoints.

Changes: Cursor validation

Layer / File(s) Summary
Paginator validation and endpoint coverage
apps/api/plane/utils/global_paginator.py, apps/api/plane/tests/contract/app/test_global_paginator_cursor_app.py
paginate converts cursor parsing failures and invalid page values into a ParseError with detail Invalid cursor parameter. Contract tests check that six malformed cursor values return HTTP 400 and 10:0:0 returns HTTP 200 on four endpoints.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: Minimal · up to 404da

Malformed pagination cursors now return a clear 400 error instead of a server error, and valid cursors behave as before. No merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title states the main change: globally paginated endpoints now return HTTP 400 for a bad cursor instead of 500. The raw summary and PR objectives both describe this behavior, including the ParseEr…
Description check Passed The description follows the repository template. It has a Description section that explains the change, the bad-cursor cases, and the affected endpoints. The Type of Change section marks Bug fix. The …
Linked Issues check Passed Issue #10486 requires HTTP 400 instead of 500 for malformed cursors, zero or negative page sizes, and negative pages on the four global paginator endpoints. Valid cursor 10:0:0 must still return 200…
Out of Scope Changes check Passed The whole-PR diff against the merge base 3ad2c27 changes two files. plane/utils/global_paginator.py adds the ParseError import and the validation described above. The new contract test file exer…
Full details: Title check

Explanation

The title states the main change: globally paginated endpoints now return HTTP 400 for a bad cursor instead of 500. The raw summary and PR objectives both describe this behavior, including the ParseError for malformed cursors, non-positive page sizes, and negative pages. The 'fix(api)' prefix is a conventional-commit style that the title follows.

Full details: Description check

Explanation

The description follows the repository template. It has a Description section that explains the change, the bad-cursor cases, and the affected endpoints. The Type of Change section marks Bug fix. The Test Scenarios section lists the new contract tests, lint results, and the backend suite run. The References section links Fixes #10486. The Screenshots and Media section is absent, which is acceptable because it applies only when relevant.

Full details: Linked Issues check

Explanation

Issue #10486 requires HTTP 400 instead of 500 for malformed cursors, zero or negative page sizes, and negative pages on the four global paginator endpoints. Valid cursor 10:0:0 must still return 200.

At the reviewed head, apps/api/plane/utils/global_paginator.py paginate wraps PaginateCursor.from_string in try/except ValueError and raises ParseError(detail="Invalid cursor parameter."). This covers inputs such as abc, which fail the format check. After parsing, the code raises the same ParseError when current_page_size <= 0 or current_page < 0. This blocks the ZeroDivisionError from ceil(total_results / page_size) and the negative slice failure. The four endpoints share this function, so the fix covers all of them. Valid cursors follow the unchanged flow. The contract test file plane/tests/contract/app/test_global_paginator_cursor_app.py is described as asserting the six bad cursors return 400 and 10:0:0 returns 200. I did not inspect that file's contents; this verdict relies on the paginator code and the PR summary for the test behavior.

Full details: Out of Scope Changes check

Explanation

The whole-PR diff against the merge base 3ad2c27 changes two files. plane/utils/global_paginator.py adds the ParseError import and the validation described above. The new contract test file exercises the four endpoints named in #10486. Both changes directly implement the linked issue. No unrelated changes were found in the reviewed evidence.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1f30bc97-ad94-45a5-95bc-12b60909dac0
Commits

Reviewing files that changed from the base of the PR and between 3ad2c27 and 404daf0.

Files selected for processing: 2

  • apps/api/plane/tests/contract/app/test_global_paginator_cursor_app.py
  • apps/api/plane/utils/global_paginator.py

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug]: Malformed cursor returns 500 on v2 work items and work item version endpoints

2 participants